use serde::{Deserialize, Serialize};

use crate::database::{self, table::image::model::NewImage};

#[derive(Debug, Serialize, Deserialize)]
pub struct ImageForm {
    pub id: i32,
    pub pid: i32,
    pub url: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct NewImageForm {
    pub pid: i32,
    pub url: String,
}

impl From<&database::table::image::model::Image> for ImageForm {
    fn from(image: &database::table::image::model::Image) -> Self {
        ImageForm {
            id: image.id,
            pid: image.pid,
            url: image.url.clone(),
        }
    }
}

impl From<ImageForm> for NewImageForm {
    fn from(image: ImageForm) -> Self {
        NewImageForm {
            pid: image.pid,
            url: image.url,
        }
    }
}

impl NewImageForm {
    pub fn to(&self) -> NewImage {
        NewImage {
            pid: self.pid,
            url: self.url.clone(),
        }
    }
}
